import 'package:enterprise_v6_app/app/components/dialog/exit_tips.dart';
import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/special_list/process_list_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/ticket_plan_entity.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:get/get.dart';

class ProcessAllocationController extends GetxController {
  TicketPlanReceiptLists ticketPlanReceipt =
      Get.arguments as TicketPlanReceiptLists; //小票数据

  Map<String, dynamic> queryParameters = {}; // 请求参数
  List<ProcessListEntity> selectedList = []; // 选中的列表

  /// 获取部门和区域列表数据
  Future<List<ProcessListEntity>> getData(int pageNum, int pageSize,
      {String? search}) async {
    queryParameters['pageNum'] = pageNum;
    queryParameters['pageSize'] = pageSize;
    queryParameters['affiliatedSystem'] = 2;
    queryParameters['name'] = search;
    // 获取流程模板接口
    final res = await HttpUtil()
        .generateGetRequest<List<ProcessListEntity>>(Interface.getProcessByPage,
            queryParameters: queryParameters)
        .execute();

    List<ProcessListEntity>? data;
    res.onSuccess((result) {
      data = result.data;
    });
    return data ?? [];
  }

  /// 选择点击事件
  void onTap(ProcessListEntity item) {
    for (var selectItem in selectedList) {
      //清空之前选中的数据
      selectItem.setIsChecked(false);
    }
    item.setIsChecked(true);
    selectedList.clear();
    selectedList.add(item);
    update();
  }

  // 下一步
  void nextStep() {
    if (selectedList.isEmpty) {
      AppToast.show('请先选择流程模板');
      return;
    }
    Get.toNamed(AppRoutes.personnelAllocationApply, arguments: {
      'processListEntity': selectedList[0],
      'ticketPlanReceipt':ticketPlanReceipt
    });
  }

  void showDetailDialog(ProcessListEntity item) {
    Get.dialog(
      ExitTips(
        title: '简介',
        content: item.remark,
        func: (b) {},
      ),
    );
  }
}
